/*
 * usart_light.c
 * Copyright (C) 2021 2021-05-27 11:10 kalipy <kalipy@debian>
 *
 * Distributed under terms of the MIT license.
 */

#include "usart_light.h"
#include "key.h"
#include "led.h"

char cmd[6] = {0xBD, 0x20, 0x00, 0x01, 0x01, 0xBE};

static void key_handler(void)
{
    int keyx_status = -1;
    while(1) {
        LOS_TaskDelay(5);
        keyx_status = drv_get_key();
        switch (keyx_status)
        {
            case key0:
                drv_led_toggle(led0_pin);
                printf("key0 pressed, send cmd to light module\r\n");
                at_usart_light_send(cmd, 6);
                break;
            case key1:
                drv_led_toggle(led1_pin);
                printf("key1 pressed, send cmd to light module\r\n");
                at_usart_light_send(cmd, 6);
                break;
            case key2:
                drv_led_toggle(led2_pin);
                printf("key2 pressed, send cmd to light module\r\n");
                at_usart_light_send(cmd, 6);
                break;
            case key3:
                printf("key3 pressed, send cmd to light module\r\n");
                at_usart_light_send(cmd, 6);
                //    drv_beep_toggle();
                //    //flag = !flag;
                break;
        }
    }
}

uint32_t create_at_key_task(void)
{
    UINT32 uwRet = 0;
    UINT32 uwTask1;
    TSK_INIT_PARAM_S stInitParam1;

    stInitParam1.usTaskPrio = 4;
    stInitParam1.uwStackSize = 0x400;
    stInitParam1.pcName = "at_key_handler";

    stInitParam1.pfnTaskEntry = key_handler;
    uwRet = LOS_TaskCreate(&uwTask1, &stInitParam1);
    if(uwRet != LOS_OK)
    {
        printf("at_key task Create failed\r\n");
    }
}
